﻿@using Library
@model Ecommerce.Models.EditProductViewModel

@{
    ViewBag.Title = NOWCulture.GetString("Create new") + "/" + NOWCulture.GetString("Edit") + " " + NOWCulture.GetString("product");
    Layout = "_Layout.cshtml";

    var productCategoryList = ViewBag.ProductCategoryList as List<SelectListItem>;
    var brandList = ViewBag.BrandList as List<SelectListItem>;
    var statusList = ViewBag.StatusList as List<SelectListItem>;
}

<h2>@ViewBag.Title</h2>
@using (Html.BeginForm("EditProduct", "Admin", FormMethod.Post, new { @id = "product-form", @class = "form-horizontal", @data_modelid = (ViewBag.IsEdit ? Model.Id.ToString() : "-1"), @enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    if (ViewBag.IsEdit)
    {
        @Html.HiddenFor(m => m.Id)
    }
    @Html.HiddenFor(m => m.Culture)
    <div class="form-group">
        <div class="pull-left">
            <a class="btn btn-warning" href="@Url.Action("Products")" title="@NOWCulture.GetString("Go back")"><span class="glyphicon glyphicon-arrow-left"></span> @NOWCulture.GetString("Go back")</a>
        </div>
        <div class="pull-right">
            <input type="reset" class="btn btn-default" value="@NOWCulture.GetString("Reset")">
            <input type="submit" class="btn btn-primary" value="@NOWCulture.GetString("Save")">
        </div>
        <div class="clearfix"></div>
    </div>
    if (productCategoryList != null && productCategoryList.Count > 0)
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Product category")</label>
            <div class="col-sm-10">
                @Html.DropDownListFor(m => m.ProductCategoryId, productCategoryList, new { @class = "form-control select2" })
                @Html.ValidationMessageFor(m => m.ProductCategoryId, "", new { @class = "text-danger" })
            </div>
        </div>
    }
    if (brandList != null && brandList.Count > 0)
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Brand")</label>
            <div class="col-sm-10">
                @Html.DropDownListFor(m => m.BrandId, brandList, new { @class = "form-control select2" })
                @Html.ValidationMessageFor(m => m.BrandId, "", new { @class = "text-danger" })
            </div>
        </div>
    }
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Price")</label>
        <div class="col-sm-10">
            <div class="input-group">
                @Html.TextBoxFor(m => m.PriceDisplay, new { @class = "form-control" })
                <div class="input-group-addon">@Settings.DefaultCurrency</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Strikethrough price")</label>
        <div class="col-sm-10">
            <div class="input-group">
                @Html.TextBoxFor(m => m.StrikethroughPriceDisplay, new { @class = "form-control" })
                <div class="input-group-addon">@Settings.DefaultCurrency</div>
            </div>
        </div>
    </div>
    if (statusList != null && statusList.Count > 0)
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Status")</label>
            <div class="col-sm-10">
                @Html.DropDownListFor(m => m.Status, statusList, new { @class = "form-control select2" })
            </div>
        </div>
    }
    <div class="form-group">
        <div class="pull-right langarea">
            @foreach (var dic in NOWCulture.Dictionary)
            {
                var langName = NOWCulture.GetString(dic.Key.Name);
                if (dic.Key.Id == Model.Culture)
                {
                    <a class="btn btn-primary btn-xs" href="@Url.Action("EditProduct", new {@id = Model.Id, @selectedCulture = dic.Key.Id})"><img src="~/Content/cultures/@dic.Key.Id/icon.png" alt="@langName" width="16" height="16" /> @langName</a>
                }
                else
                {
                    <a class="btn btn-default btn-xs" href="@Url.Action("EditProduct", new { @id = Model.Id, @selectedCulture = dic.Key.Id })"><img src="~/Content/cultures/@dic.Key.Id/icon.png" alt="@langName" width="16" height="16" /> @langName</a>
                }
            }
        </div>
    </div>
    <div class="form-group clearfix">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Name")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("URL")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.Url, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.Url, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Description")</label>
        <div class="col-sm-10">
            @Html.TextAreaFor(m => m.Description, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.Description, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Keywords")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.Keywords, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.Keywords, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Webpage title")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.WebTitle, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.WebTitle, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Webpage description")</label>
        <div class="col-sm-10">
            @Html.TextAreaFor(m => m.WebDescription, new {@class = "form-control"})
            @Html.ValidationMessageFor(m => m.WebDescription, "", new {@class = "text-danger"})
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Ad banner")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.Banner, new { @type = "file", @accept = "image/*", @class = "form-control", @title = NOWCulture.GetString("Browse an image to upload") })
            @if (!string.IsNullOrWhiteSpace(Model.BannerSrc))
            {
                <img id="previewImg" src="@Model.BannerSrc" alt="@Model.BannerSrc"/>
            }
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Ad banner caption")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.BannerCaption, new {@class = "form-control"})
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Ad banner ALT (HTML attribute) text")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.BannerAlt, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Ad URL")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.BannerUrl, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Promotion caption")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.PromotionCaption, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Promotion details")</label>
        <div class="col-sm-10">
            @Html.EditorFor(m => m.PromotionDetails, "Html", new { @row = 4 })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Policies")</label>
        <div class="col-sm-10">
            @Html.EditorFor(m => m.Policies, "Html", new { @row = 4 })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Small article")</label>
        <div class="col-sm-10">
            @Html.EditorFor(m => m.SmallArticle, "Html", new { @row = 4 })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Article")</label>
        <div class="col-sm-10">
            @Html.EditorFor(m => m.Article, "Html", new { @row = 10 })
        </div>
    </div>
    @Html.ValidationSummary(true, "", new { @class = "bg-danger" })
    <div class="form-group">
        <div class="pull-left">
            <a class="btn btn-warning" href="@Url.Action("Products")" title="@NOWCulture.GetString("Go back")"><span class="glyphicon glyphicon-arrow-left"></span> @NOWCulture.GetString("Go back")</a>
        </div>
        <div class="pull-right">
            <input type="reset" class="btn btn-default" value="@NOWCulture.GetString("Reset")">
            <input type="submit" class="btn btn-primary" value="@NOWCulture.GetString("Save")">
        </div>
        <div class="clearfix"></div>
    </div>
}

@section styles
{
    @(HttpContext.Current.IsDebuggingEnabled ? Styles.Render("~/Content/admin-edit-product") : Scripts.RenderFormat(@"<link href=""{0}"" rel=""stylesheet"" />", "~/Content/admin-edit-product"))
}
@section scripts
{
    <script>
        document.currentCulture = '@NOWCulture.CurrentCulture';
        document.twoLetterISOLanguageName = '@NOWCulture.CurrentCultureInfo.TwoLetterISOLanguageName';
        document.contentCssLink = '@Styles.Url("~/Content/css")';
        document.simpleImageBrowserURL = '@(Model.Id > 0 ? Url.Action("ImageBrowser", "Shared", new { @imageDirectoryUrl = Settings.ProductImageDiretories + Model.Id }) : "")';
        document.simpleImageBrowserUploadActionURL = '@(Model.Id > 0 ? Url.Action("UploadImages", "Shared", new { @imageDirectoryUrl = Settings.ProductImageDiretories + Model.Id }) : "")';
    </script>
    @(HttpContext.Current.IsDebuggingEnabled ? Scripts.Render("~/bundles/admin-edit-product") : Scripts.RenderFormat(@"<script src=""{0}"" async defer></script>", "~/bundles/admin-edit-product"))
    <script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
}